package com.heima.wemedia.controller.v1;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.heima.apis.wemedia.WmUserControllerApi;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserService userService;

    @PostMapping("/save")
    @Override
    @Transactional
    @LcnTransaction
    public ResponseResult save(@RequestBody WmUser wmUser){
        userService.save(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @GetMapping("/findByName/{name}")
    @Override
    public ResponseResult findByName(@PathVariable("name") String name){
       return userService.findByName(name);
    }

    /**
     * 按照id查询用户
     * @param id
     * @return
     */
    @GetMapping("/findByUserId/{id}")
    @Override
    public ResponseResult findById(@PathVariable("id") Integer id) {
        return userService.findById(id);
    }
}